package com.TheyChat.service.config.auth;


import com.TheyChat.service.config.auth.entity.UserAuthInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;



/***
 * 认证用户信息上下文
 */
public class UserContext {
    /****
     * 获取当前认证的用户信息
     * @return
     */
    public static UserAuthInfo getCurrentUser() {
        UserAuthInfo res = null;
        if (RequestContextHolder.getRequestAttributes() != null) {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            String token = request.getHeader(AuthenticationInterceptor.ACCESS_TOKEN);
            System.out.println(token);
            res = AuthUtils.hasAuth(token);
        }
        return res;
    }
}
